/**
 * 
 */
package hu.gbalage.owl.cms.core;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author balage
 *
 */
public class Config {

	public static final String config_file = "config.properties";
	
	public static final String cache_basedir = "cms.cache.basedir";
	
	private Config(){
		
	}
	
	private static Properties config = new Properties();

	static{
		try {
			config.load(new FileInputStream(config_file));
		} catch (FileNotFoundException e) {
			defaults();
			//e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private static void defaults(){
		setProperty(cache_basedir, new File("owl").getAbsolutePath());
		//save();
	}
	
	private static void save(){
		try {
			config.store(new FileOutputStream(config_file), "");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static String getProperty(String key) {
		return config.getProperty(key);
	}

	public static void setProperty(String key, String value) {
		config.setProperty(key, value);
		save();
	}
	
	
	
}
